﻿using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using HslCommunication.Core;
using HslCommunication.Reflection;
using HslCommunication.Serial;

namespace HslCommunication.Profinet.Melsec
{
	/// <summary>
	/// 三菱的串口通信的对象，适用于读取FX系列的串口数据，支持的类型参考文档说明<br />
	/// Mitsubishi's serial communication object is suitable for reading serial data of the FX series. Refer to the documentation for the supported types.
	/// </summary>
	/// <remarks>
	/// <inheritdoc cref="T:HslCommunication.Profinet.Melsec.MelsecFxSerialOverTcp" path="remarks" />
	/// </remarks>
	/// <example>
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\MelsecFxSerial.cs" region="Usage" title="简单的使用" />
	/// </example>
	// Token: 0x02000076 RID: 118
	public class MelsecFxSerial : SerialDeviceBase
	{
		/// <summary>
		/// 实例化一个默认的对象
		/// </summary>
		// Token: 0x060009AD RID: 2477 RVA: 0x0003975B File Offset: 0x0003795B
		public MelsecFxSerial()
		{
			base.ByteTransform = new RegularByteTransform();
			base.WordLength = 1;
			this.IsNewVersion = true;
			base.ByteTransform.IsStringReverseByteWord = true;
		}

		/// <inheritdoc cref="P:HslCommunication.Profinet.Melsec.MelsecFxSerialOverTcp.IsNewVersion" />
		// Token: 0x1700019B RID: 411
		// (get) Token: 0x060009AE RID: 2478 RVA: 0x0003978E File Offset: 0x0003798E
		// (set) Token: 0x060009AF RID: 2479 RVA: 0x00039796 File Offset: 0x00037996
		public bool IsNewVersion { get; set; }

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecFxSerialOverTcp.Read(System.String,System.UInt16)" />
		// Token: 0x060009B0 RID: 2480 RVA: 0x0003979F File Offset: 0x0003799F
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			return MelsecFxSerialOverTcp.ReadHelper(address, length, new Func<byte[], OperateResult<byte[]>>(base.ReadBase), this.IsNewVersion);
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecFxSerialOverTcp.Write(System.String,System.Byte[])" />
		// Token: 0x060009B1 RID: 2481 RVA: 0x000397BA File Offset: 0x000379BA
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			return MelsecFxSerialOverTcp.WriteHelper(address, value, new Func<byte[], OperateResult<byte[]>>(base.ReadBase), this.IsNewVersion);
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecFxSerialOverTcp.ReadBool(System.String,System.UInt16)" />
		// Token: 0x060009B2 RID: 2482 RVA: 0x000397D5 File Offset: 0x000379D5
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			return MelsecFxSerialOverTcp.ReadBoolHelper(address, length, new Func<byte[], OperateResult<byte[]>>(base.ReadBase));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecFxSerialOverTcp.Write(System.String,System.Boolean)" />
		// Token: 0x060009B3 RID: 2483 RVA: 0x000397EA File Offset: 0x000379EA
		[HslMqttApi("WriteBool", "")]
		public override OperateResult Write(string address, bool value)
		{
			return MelsecFxSerialOverTcp.WriteHelper(address, value, new Func<byte[], OperateResult<byte[]>>(base.ReadBase));
		}

		/// <inheritdoc />
		// Token: 0x060009B4 RID: 2484 RVA: 0x00039800 File Offset: 0x00037A00
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool value)
		{
			MelsecFxSerial.<WriteAsync>d__9 <WriteAsync>d__ = new MelsecFxSerial.<WriteAsync>d__9();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<MelsecFxSerial.<WriteAsync>d__9>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x060009B5 RID: 2485 RVA: 0x00039852 File Offset: 0x00037A52
		public override string ToString()
		{
			return string.Format("MelsecFxSerial[{0}:{1}]", base.PortName, base.BaudRate);
		}
	}
}
